package com.westinyang.jsapp;

import ohos.ace.ability.AceAbility;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbility extends AceAbility {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onBackPressed() {
        // super.onBackPressed();
        exit();
    }

    // 两次返回键退出
    private long exitTime = 0;
    public void exit() {
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            new ToastDialog(getContext())
                    .setText("再按一次返回键退出")
                    .setDuration(2000)
                    //.setAlignment(LayoutAlignment.CENTER)
                    .setOffset(0, 200)
                    .show();
            exitTime = System.currentTimeMillis();
        } else {
            // finish();
            System.exit(0);
        }
    }
}
